/**
 * Color Service
 * 颜色选择服务， 提供各类颜色处理效果
 */

angular.module('JiangGanApp')
  .service('ColorService', ColorService);

function ColorService() {

  //颜色变化计算 从绿到红
  this.getColorGR = function (v2, colorIndex) {
    if(v2 < colorIndex * 2){
      var red = v2 > colorIndex ? 0.9 : v2 / colorIndex;
      var green = v2 < colorIndex ? 0.64 : (colorIndex * 2 - v2) / colorIndex * 0.54 + 0.1;
    }
    else {
      var red = 1;
      var green = 0;
    }
    var blue = 0.3;
    return [red, green, blue];
  }

  //颜色变化计算 从黄到红
  this.getColorYR = function (v2, colorIndex) {
    var color = 2 * colorIndex;
    if(v2 < color){
      var red = (color - v2) / color * 0.1 + 0.9;
      var green = (color - v2) / color;
      var blue = (color - v2) / color * 0.51;
    }
    else {
      var red = 0.9;
      var green = 0;
      var blue = 0;
    }
    return [red, green, blue];
  }

  //颜色变化计算 从蓝到黄到红
  this.getColorBR = function (v2, colorIndex) {
    if(v2 < colorIndex * 2){
      var red = v2 > colorIndex ? (colorIndex * 2 - v2) / colorIndex * 0.1 + 0.9 : v2 / colorIndex * 0.9 + 0.1;
      var green = v2 > colorIndex ? (colorIndex * 2 - v2) / colorIndex * 0.9 + 0.1 : v2 / colorIndex * 0.5 + 0.5;
      var blue = (colorIndex * 2 - v2) / colorIndex * 0.3 + 0.1;
    }
    else {
      var red = 0.9;
      var blue = 0.1;
      var green = 0.1;
    }
    
    return [red, green, blue];
  }

  //color: ['#ff3333', 'orange', 'yellow','lime','#00FF99'],
  this.getColorDark = function (v2, max) {
    var percent = Math.floor(v2 / max * 5);
    switch(percent) {
      case 0:
        return '#00FF99';
      case 1:
        return 'lime';
      case 2:
        return 'yellow';
      case 3:
        return 'orange';
      default:
        return '#ff3333';
    }
  }

  //color: ['#FF6024', '#FFB033', '#FDE944','#DCFF51','#81FF51'],
  this.getColorArea = function (v2, max) {
    var percent = Math.floor(v2 / max * 5);
    switch(percent) {
      case 0:
        return '#81FF51';
      case 1:
        return '#DCFF51';
      case 2:
        return '#FDE944';
      case 3:
        return '#FFB033';
      default:
        return '#FF6024';
    }
  }

  //黄色：F1FF00  黑蓝：0053B4  淡蓝：00B2F0
  //蓝青：01F4FF  绿：00FF53  边界颜色：0008FF
  this.getColorDark2 = function (v2, max) {
    var percent = Math.floor(v2 / max * 5);
    switch(percent) {
      case 0:
        return '#00FF53';
      case 1:
        return '#F1FF00';
      case 2:
        return '#00B2F0';
      case 3:
        return '#01F4FF';
      default:
        return '#0053B4';
    }
  }


}
